<%@ page language="java" contentType="text/html; charset=windows-1255" pageEncoding="windows-1255"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<!-- RichFaces tag library declaration -->
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

 <script type="text/javascript">
            function fillCst(loc,id, sgcomponent){
            	loc.value =sgcomponent.getSelectedItems().pluck('location');
            	id.value =sgcomponent.getSelectedItems().pluck('id');
            }
            function fillPrd(name,id, sgcomponent){
            	name.value =sgcomponent.getSelectedItems().pluck('productName');
            	id.value =sgcomponent.getSelectedItems().pluck('id');
            }
            
        </script>
      <f:view>
           <%@include file="../inc/menu.inc" %>
            <f:loadBundle basename="il" var="mes" />
                  <a4j:form>
             		    <a4j:keepAlive beanName="newDPARequestManagedBean" />
             		    <h:outputText style="font-size:30;color:#680000" value="#{mes.menu_new_dpa}" />
             		    <br>
             		    <br>
             		    <h:panelGrid columns="2">
             		    <rich:comboBox value="#{newDPARequestManagedBean.selectedDraft}">           
             		    	<f:selectItems    value="#{newDPARequestManagedBean.draftsLabel}"  var = "draft" itemLabel="#{draft.value}" itemValue="#{draft.value}" />            
             		    </rich:comboBox>
             		    
             		    <a4j:commandButton value="#{mes.load_draft}" action="#{newDPARequestManagedBean.loadDraft}" reRender="dpaPan" />
             		    </h:panelGrid>
                        <br>
                        <rich:panel id="dpaPan" header="New DPA Request" style="width: 900px">
                            <h:outputText value="#{mes.date_request}" />

       
                        <rich:calendar value="#{newDPARequestManagedBean.requestDate}" /> 
                           
       
                        <br>
                        <br>
                        <!--   <h:outputText value="#{mes.distrib_name}"  /> &nbsp;
                        <h:inputText value = "#{newDPARequestManagedBean.distrib_name}"/>&nbsp;-->
                        <h:outputText value="#{mes.contact} " />&nbsp;
                        <h:inputText value="#{newDPARequestManagedBean.contact}" />&nbsp;
                        <h:outputText value="#{mes.email} " />&nbsp;
                        <h:inputText value="#{newDPARequestManagedBean.email}" id="email">
                        	<rich:ajaxValidator event="onblur"/>
                        </h:inputText>&nbsp;
                        <h:outputText value="#{mes.emailcc} " />&nbsp;
                 	  	<h:inputText value="#{newDPARequestManagedBean.cc}"  id="emailcc">
                 	  		<rich:ajaxValidator event="onblur"/>
                 	  	</h:inputText>&nbsp; 
                        
                        <rich:message for="email" style="color:red;" />&nbsp;&nbsp; 
                        <rich:message for="emailcc" style="color:red;" />
                        <br>
                        <br> 
                        <h:outputText value="#{mes.dialogic_fse} " />&nbsp;
                        <h:inputText value="#{newDPARequestManagedBean.dialogic_fse}" />&nbsp;
       
                        <br>
                        <br>
                        <font size="4" color="red">*</font>
                        <h:outputText value="#{mes.customer_name} " />&nbsp;


                        <h:inputText id="customerI" value="#{newDPARequestManagedBean.customer_name}" />
                         <rich:suggestionbox for="customerI" var="customer" suggestionAction="#{newDPARequestManagedBean.autoCompleteCustomer}" usingSuggestObjects="true" onobjectchange="fillCst(#{rich:element('customerL')}, #{rich:element('customerID')},#{rich:component('suggestionC')});" id="suggestionC">
                         
                             <h:column>
                            <h:outputText value="#{customer.name}" />
                            </h:column>
                            
                         </rich:suggestionbox>
                       
                        <h:outputText value="#{mes.customer_loc} " />&nbsp;
                        <h:inputText id="customerL" value="#{newDPARequestManagedBean.customer_location}" />&nbsp;
                       
                       <h:inputHidden id="customerID" value="#{newDPARequestManagedBean.customer_id}" />
                        
                        <br>
                        <br>
                        <h:outputText value="#{mes.end_user_name} " />&nbsp;
                        <h:inputText value="#{newDPARequestManagedBean.end_user_name}" />&nbsp;
                       
                        <br><br>
                        <h:outputText value="#{mes.reason_req} " />&nbsp;
                        <rich:comboBox defaultLabel="" value="#{newDPARequestManagedBean.reason_req}">
                            <f:selectItem itemValue="#{mes.ext_req}" />
                            <f:selectItem itemValue="#{mes.meet_comp}" />
                            <f:selectItem itemValue="#{mes.nfr_sample_demo}" />
                            <f:selectItem itemValue="#{mes.other}" />
                            <f:selectItem itemValue="#{mes.volume}" />
                          </rich:comboBox>&nbsp;
                         
                        <br><br>
                        <h:outputText value="#{mes.info} " />&nbsp;                       
                        <h:inputTextarea style="width : 500px" value="#{newDPARequestManagedBean.info}" />&nbsp;
                        <h:outputText value="#{mes.dpa_exp_date }" />&nbsp;  
                        <rich:calendar  value="#{newDPARequestManagedBean.expDate}" />&nbsp; 
                        
                        <br><br>
                        <h:outputText value="#{mes.data_table} " />&nbsp;
                        <rich:panel>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        	<h:outputText value="#{mes.dialogic_item}    " />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        	<h:outputText value="#{mes.product_name} " />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        	<h:outputText value="#{mes.sdc} " />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        	<h:outputText value="#{mes.traget_cost} " />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        	<h:outputText value="#{mes.competitor} " />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        	<h:outputText value="#{mes.comp_price} " />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        	<h:outputText value="#{mes.qty} " />&nbsp;   
                            <h:panelGrid id="product_line" columns="11">
                                <font size="4" color="red">*</font>
                                <h:inputText id="prd_key" value="#{newDPARequestManagedBean.dialogic_Item }" />
                         		<rich:suggestionbox for="prd_key" var="product_item" suggestionAction="#{newDPARequestManagedBean.autoCompleteProducts}" usingSuggestObjects="true" onobjectchange="fillPrd(#{rich:element('prd_name')},#{rich:element('prd_id')},#{rich:component('suggestionP')});" id="suggestionP">
                          		   <h:column>
                            			<h:outputText value="#{product_item.dialogicItemKey}" />
                            		</h:column>
                         		</rich:suggestionbox>
                                
                                
                                <h:inputText id="prd_name" value="#{newDPARequestManagedBean.product_Name}" />
                               	<h:inputHidden id="prd_id" value="#{newDPARequestManagedBean.product_id}" />
                                <h:inputText value="#{newDPARequestManagedBean.SDC }" style="width : 70px" />
                                <h:inputText value="#{newDPARequestManagedBean.traget_Cost}" style="width : 70px" />
                                <h:inputText value="#{newDPARequestManagedBean.competitor }" style="width : 150px" />
                                <h:inputText value="#{newDPARequestManagedBean.competitors_Price}" style="width : 100px" />
                                <h:inputText value="#{newDPARequestManagedBean.qty}" style="width : 70px" />
                                <!--<h:inputText value="#{newDPARequestManagedBean.approvedPrice}" style="width : 70px"/>  -->
                                <a4j:commandButton value="+" action="#{newDPARequestManagedBean.add}" reRender="list, product_line" />
                            </h:panelGrid>
                            <rich:dataTable id="list" value="#{newDPARequestManagedBean.productList}" 
                            rowKeyVar="row" var="itm" width="800px">
 							<rich:column style="width : 50px">
                                    <h:outputText value="#{row }" />
                                </rich:column>
                                <rich:column style="width : 150px">
                                    <h:outputText value="#{itm.product.dialogicItemKey}" />
                                </rich:column>
                                <rich:column style="width : 170px">
                                    <h:outputText value="#{itm.product.productName}" />
                                </rich:column>
                                <rich:column style="width : 80px">
                                    <h:outputText value="#{itm.sdc}" />
                                </rich:column>
                                <rich:column style="width : 80px">
                                    <h:outputText value="#{itm.targetCost}" />
                                </rich:column>
                                <rich:column style="width : 110px">
                                    <h:outputText value="#{itm.competitor}" />
                                </rich:column>
                                <rich:column style="width : 110px">
                                    <h:outputText value="#{itm.competitorsPrice}" />
                                </rich:column>
                                <rich:column style="width : 80px">
                                    <h:outputText value="#{itm.quantity}" />
                                </rich:column>
                                <rich:column style="width : 80px">
                                    <a4j:commandLink value="#{mes.remove }" action="#{newDPARequestManagedBean.removePrd}"  reRender="list">
				                			<a4j:actionparam  value="#{row }" assignTo="#{newPosManagedBean.removePrdIdx}"/>
					            		</a4j:commandLink>
                                </rich:column>
                                                              
                            </rich:dataTable>
                        </rich:panel>
                                          
               
               
                       
                        <br><br><br>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <!--<h:commandButton action="#{newDPARequestManagedBean.doAc}" value="Cancel " /> &nbsp;&nbsp;-->
                        <h:commandButton action="#{newDPARequestManagedBean.createRequest}" value="#{mes.dpa_create }" onclick="return confirm('#{mes.prompt }')" />&nbsp;&nbsp;
                        <h:commandButton action="#{newDPARequestManagedBean.createDraft}" value="#{mes.dpa_save_draft }"  onclick="return confirm('#{mes.prompt }')"  />&nbsp;&nbsp;
                     
                        <!-- <h:commandButton action="#{newDPARequestManagedBean.doAc}" value="Reset" />&nbsp;&nbsp;-->
                        <!--<h:commandButton action="#{newDPARequestManagedBean.doAc}" value="Save" /> -->
                        </rich:panel>
                        
                        <rich:extendedDataTable id="olddpa" value="#{newDPARequestManagedBean.olddpas}" var="dpa" width="660px" height="400px"  
			        	columnClasses="center"  reRender="ds">
			            	<rich:column sortBy="#{dpa.dpaId}"> 
			                	<f:facet name="header">
			                    	<h:outputText value="#{mes.dpaid }"/>
			                	</f:facet>
				                <h:outputText value="#{dpa.dpaId}"/>
			            	</rich:column> 
			            	<rich:column sortBy="#{dpa.requestDate}" width="110px">
			                	<f:facet name="header">
				                    <h:outputText value="#{mes.date_request }"/>
				                </f:facet>
				                <h:outputText value="#{dpa.requestDate}"/> 
				            </rich:column>
				            <rich:column sortBy="#{dpa.customer.name}" width="110px">
				                <f:facet name="header">
				                    <h:outputText value="#{mes.customer_name}"/>
				                </f:facet>
				              			<h:outputText id="id" value="#{dpa.customer.name}"/>
				            </rich:column>
				            
				            <rich:column>
				                 <a4j:commandButton    action= "#{newDPARequestManagedBean.selectDpaFromTable}" value="#{mes.select }"  reRender="dpaPan">
				                		<a4j:actionparam name="id"  value="#{dpa.id}" assignTo="#{newDPARequestManagedBean.selectedDpaIdFormTable}"/>
				                		
					            </a4j:commandButton>
				            </rich:column>
				            <f:facet name="footer">
				                <rich:datascroller id="ds"></rich:datascroller>
				            </f:facet>
				        </rich:extendedDataTable>
                      
						</a4j:form>
            </f:view><body>
            
      </body>
      </html>